
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/03/2018 10:46:29
-- Generated from EDMX file: D:\系统模板\Bottle.CommunityForum\Bottle.CommunityForum.Model\DataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [BottleDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_UserInfoTopicsInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_topics] DROP CONSTRAINT [FK_UserInfoTopicsInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_TagsInfoTopicsInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_topics] DROP CONSTRAINT [FK_TagsInfoTopicsInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_UserInfoCommentsInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_comments] DROP CONSTRAINT [FK_UserInfoCommentsInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_TopicsInfoCommentsInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_comments] DROP CONSTRAINT [FK_TopicsInfoCommentsInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_UserInfoFavoritesInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_favorites] DROP CONSTRAINT [FK_UserInfoFavoritesInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_TopicsInfoFavoritesInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_favorites] DROP CONSTRAINT [FK_TopicsInfoFavoritesInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_UserInfoUserAttrInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_userattr] DROP CONSTRAINT [FK_UserInfoUserAttrInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_AttributesInfoUserAttrInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_userattr] DROP CONSTRAINT [FK_AttributesInfoUserAttrInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_TopicsInfoTopicsAttrInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_topicsattr] DROP CONSTRAINT [FK_TopicsInfoTopicsAttrInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_AttributesInfoTopicsAttrInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_topicsattr] DROP CONSTRAINT [FK_AttributesInfoTopicsAttrInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_UserInfoMessageInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_message] DROP CONSTRAINT [FK_UserInfoMessageInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_SettingsTypeInfoSettingsInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_settings] DROP CONSTRAINT [FK_SettingsTypeInfoSettingsInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_PageInfoNodesInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_nodes] DROP CONSTRAINT [FK_PageInfoNodesInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_tb_UserRole_UserInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_UserRole] DROP CONSTRAINT [FK_tb_UserRole_UserInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_tb_UserRole_RoleInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[tb_UserRole] DROP CONSTRAINT [FK_tb_UserRole_RoleInfo];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[tb_users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_users];
GO
IF OBJECT_ID(N'[dbo].[tb_role]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_role];
GO
IF OBJECT_ID(N'[dbo].[tb_topics]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_topics];
GO
IF OBJECT_ID(N'[dbo].[tb_tags]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_tags];
GO
IF OBJECT_ID(N'[dbo].[tb_comments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_comments];
GO
IF OBJECT_ID(N'[dbo].[tb_favorites]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_favorites];
GO
IF OBJECT_ID(N'[dbo].[tb_attributes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_attributes];
GO
IF OBJECT_ID(N'[dbo].[tb_userattr]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_userattr];
GO
IF OBJECT_ID(N'[dbo].[tb_topicsattr]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_topicsattr];
GO
IF OBJECT_ID(N'[dbo].[tb_message]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_message];
GO
IF OBJECT_ID(N'[dbo].[tb_settingstype]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_settingstype];
GO
IF OBJECT_ID(N'[dbo].[tb_settings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_settings];
GO
IF OBJECT_ID(N'[dbo].[tb_nodes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_nodes];
GO
IF OBJECT_ID(N'[dbo].[tb_page]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_page];
GO
IF OBJECT_ID(N'[dbo].[tb_UserRole]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_UserRole];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'tb_users'
CREATE TABLE [dbo].[tb_users] (
    [userid] int IDENTITY(1,1) NOT NULL,
    [username] nvarchar(20)  NULL,
    [userpwd] varchar(32)  NULL,
    [email] varchar(50)  NULL,
    [headimgurl] varchar(100)  NULL,
    [gender] int  NULL,
    [topics] int  NULL,
    [replies] int  NULL,
    [favorites] int  NULL,
    [createtime] datetime  NULL,
    [lastlogintime] datetime  NULL,
    [state] int  NULL,
    [isonline] int  NULL
);
GO

-- Creating table 'tb_role'
CREATE TABLE [dbo].[tb_role] (
    [roleid] int IDENTITY(1,1) NOT NULL,
    [rolename] nchar(20)  NULL,
    [content] nchar(200)  NULL
);
GO

-- Creating table 'tb_topics'
CREATE TABLE [dbo].[tb_topics] (
    [topicsid] int IDENTITY(1,1) NOT NULL,
    [topicsname] nvarchar(20)  NULL,
    [keywords] nvarchar(50)  NULL,
    [content] nvarchar(max)  NULL,
    [createtime] datetime  NULL,
    [updatetime] datetime  NULL,
    [lastreply] datetime  NULL,
    [comments] int  NULL,
    [favorites] int  NULL,
    [state] int  NULL,
    [tb_userid] int  NOT NULL,
    [tb_tagsid] int  NOT NULL
);
GO

-- Creating table 'tb_tags'
CREATE TABLE [dbo].[tb_tags] (
    [tagsid] int IDENTITY(1,1) NOT NULL,
    [tagsname] nvarchar(20)  NULL,
    [topics] int  NULL
);
GO

-- Creating table 'tb_comments'
CREATE TABLE [dbo].[tb_comments] (
    [commentsid] int IDENTITY(1,1) NOT NULL,
    [content] nvarchar(500)  NULL,
    [createtime] datetime  NULL,
    [tb_userid] int  NOT NULL,
    [tb_topicsid] int  NOT NULL
);
GO

-- Creating table 'tb_favorites'
CREATE TABLE [dbo].[tb_favorites] (
    [favoritesid] int IDENTITY(1,1) NOT NULL,
    [content] nvarchar(200)  NULL,
    [createtime] datetime  NULL,
    [tb_userid] int  NOT NULL,
    [tb_topicsid] int  NOT NULL
);
GO

-- Creating table 'tb_attributes'
CREATE TABLE [dbo].[tb_attributes] (
    [attributesid] int IDENTITY(1,1) NOT NULL,
    [attributesname] varchar(32)  NULL,
    [content] nvarchar(200)  NULL,
    [cratetime] datetime  NULL
);
GO

-- Creating table 'tb_userattr'
CREATE TABLE [dbo].[tb_userattr] (
    [userattrid] int IDENTITY(1,1) NOT NULL,
    [value] nvarchar(200)  NULL,
    [tb_userid] int  NOT NULL,
    [tb_attributesid] int  NOT NULL
);
GO

-- Creating table 'tb_topicsattr'
CREATE TABLE [dbo].[tb_topicsattr] (
    [topicsattrid] int IDENTITY(1,1) NOT NULL,
    [value] nvarchar(200)  NULL,
    [tb_topicsid] int  NOT NULL,
    [tb_attributesid] int  NOT NULL
);
GO

-- Creating table 'tb_message'
CREATE TABLE [dbo].[tb_message] (
    [messageid] int IDENTITY(1,1) NOT NULL,
    [messagename] nvarchar(32)  NULL,
    [content] nvarchar(500)  NULL,
    [createtime] datetime  NULL,
    [state] int  NULL,
    [tb_userid] int  NOT NULL
);
GO

-- Creating table 'tb_settingstype'
CREATE TABLE [dbo].[tb_settingstype] (
    [settingstypeid] int IDENTITY(1,1) NOT NULL,
    [settingstypename] nvarchar(20)  NULL,
    [settingstypeno] varchar(32)  NULL
);
GO

-- Creating table 'tb_settings'
CREATE TABLE [dbo].[tb_settings] (
    [settingsid] int IDENTITY(1,1) NOT NULL,
    [settingsname] nvarchar(20)  NULL,
    [value] nvarchar(200)  NULL,
    [content] nvarchar(200)  NULL,
    [createtime] nvarchar(max)  NOT NULL,
    [state] int  NULL,
    [tb_settingstypeid] int  NOT NULL
);
GO

-- Creating table 'tb_nodes'
CREATE TABLE [dbo].[tb_nodes] (
    [nodesid] int IDENTITY(1,1) NOT NULL,
    [nodesname] nvarchar(20)  NULL,
    [keywords] nvarchar(50)  NULL,
    [content] nvarchar(200)  NULL,
    [ico] varchar(128)  NULL,
    [parent] int  NOT NULL,
    [nodesno] char(6)  NOT NULL,
    [tb_pageid] int  NOT NULL
);
GO

-- Creating table 'tb_page'
CREATE TABLE [dbo].[tb_page] (
    [pageid] int IDENTITY(1,1) NOT NULL,
    [pagename] nvarchar(20)  NULL,
    [content] nvarchar(200)  NULL,
    [gourl] varchar(128)  NULL,
    [createtime] datetime  NULL,
    [state] int  NULL
);
GO

-- Creating table 'tb_UserRole'
CREATE TABLE [dbo].[tb_UserRole] (
    [user_userid] int  NOT NULL,
    [role_roleid] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [userid] in table 'tb_users'
ALTER TABLE [dbo].[tb_users]
ADD CONSTRAINT [PK_tb_users]
    PRIMARY KEY CLUSTERED ([userid] ASC);
GO

-- Creating primary key on [roleid] in table 'tb_role'
ALTER TABLE [dbo].[tb_role]
ADD CONSTRAINT [PK_tb_role]
    PRIMARY KEY CLUSTERED ([roleid] ASC);
GO

-- Creating primary key on [topicsid] in table 'tb_topics'
ALTER TABLE [dbo].[tb_topics]
ADD CONSTRAINT [PK_tb_topics]
    PRIMARY KEY CLUSTERED ([topicsid] ASC);
GO

-- Creating primary key on [tagsid] in table 'tb_tags'
ALTER TABLE [dbo].[tb_tags]
ADD CONSTRAINT [PK_tb_tags]
    PRIMARY KEY CLUSTERED ([tagsid] ASC);
GO

-- Creating primary key on [commentsid] in table 'tb_comments'
ALTER TABLE [dbo].[tb_comments]
ADD CONSTRAINT [PK_tb_comments]
    PRIMARY KEY CLUSTERED ([commentsid] ASC);
GO

-- Creating primary key on [favoritesid] in table 'tb_favorites'
ALTER TABLE [dbo].[tb_favorites]
ADD CONSTRAINT [PK_tb_favorites]
    PRIMARY KEY CLUSTERED ([favoritesid] ASC);
GO

-- Creating primary key on [attributesid] in table 'tb_attributes'
ALTER TABLE [dbo].[tb_attributes]
ADD CONSTRAINT [PK_tb_attributes]
    PRIMARY KEY CLUSTERED ([attributesid] ASC);
GO

-- Creating primary key on [userattrid] in table 'tb_userattr'
ALTER TABLE [dbo].[tb_userattr]
ADD CONSTRAINT [PK_tb_userattr]
    PRIMARY KEY CLUSTERED ([userattrid] ASC);
GO

-- Creating primary key on [topicsattrid] in table 'tb_topicsattr'
ALTER TABLE [dbo].[tb_topicsattr]
ADD CONSTRAINT [PK_tb_topicsattr]
    PRIMARY KEY CLUSTERED ([topicsattrid] ASC);
GO

-- Creating primary key on [messageid] in table 'tb_message'
ALTER TABLE [dbo].[tb_message]
ADD CONSTRAINT [PK_tb_message]
    PRIMARY KEY CLUSTERED ([messageid] ASC);
GO

-- Creating primary key on [settingstypeid] in table 'tb_settingstype'
ALTER TABLE [dbo].[tb_settingstype]
ADD CONSTRAINT [PK_tb_settingstype]
    PRIMARY KEY CLUSTERED ([settingstypeid] ASC);
GO

-- Creating primary key on [settingsid] in table 'tb_settings'
ALTER TABLE [dbo].[tb_settings]
ADD CONSTRAINT [PK_tb_settings]
    PRIMARY KEY CLUSTERED ([settingsid] ASC);
GO

-- Creating primary key on [nodesid] in table 'tb_nodes'
ALTER TABLE [dbo].[tb_nodes]
ADD CONSTRAINT [PK_tb_nodes]
    PRIMARY KEY CLUSTERED ([nodesid] ASC);
GO

-- Creating primary key on [pageid] in table 'tb_page'
ALTER TABLE [dbo].[tb_page]
ADD CONSTRAINT [PK_tb_page]
    PRIMARY KEY CLUSTERED ([pageid] ASC);
GO

-- Creating primary key on [user_userid], [role_roleid] in table 'tb_UserRole'
ALTER TABLE [dbo].[tb_UserRole]
ADD CONSTRAINT [PK_tb_UserRole]
    PRIMARY KEY NONCLUSTERED ([user_userid], [role_roleid] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [tb_userid] in table 'tb_topics'
ALTER TABLE [dbo].[tb_topics]
ADD CONSTRAINT [FK_UserInfoTopicsInfo]
    FOREIGN KEY ([tb_userid])
    REFERENCES [dbo].[tb_users]
        ([userid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserInfoTopicsInfo'
CREATE INDEX [IX_FK_UserInfoTopicsInfo]
ON [dbo].[tb_topics]
    ([tb_userid]);
GO

-- Creating foreign key on [tb_tagsid] in table 'tb_topics'
ALTER TABLE [dbo].[tb_topics]
ADD CONSTRAINT [FK_TagsInfoTopicsInfo]
    FOREIGN KEY ([tb_tagsid])
    REFERENCES [dbo].[tb_tags]
        ([tagsid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TagsInfoTopicsInfo'
CREATE INDEX [IX_FK_TagsInfoTopicsInfo]
ON [dbo].[tb_topics]
    ([tb_tagsid]);
GO

-- Creating foreign key on [tb_userid] in table 'tb_comments'
ALTER TABLE [dbo].[tb_comments]
ADD CONSTRAINT [FK_UserInfoCommentsInfo]
    FOREIGN KEY ([tb_userid])
    REFERENCES [dbo].[tb_users]
        ([userid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserInfoCommentsInfo'
CREATE INDEX [IX_FK_UserInfoCommentsInfo]
ON [dbo].[tb_comments]
    ([tb_userid]);
GO

-- Creating foreign key on [tb_topicsid] in table 'tb_comments'
ALTER TABLE [dbo].[tb_comments]
ADD CONSTRAINT [FK_TopicsInfoCommentsInfo]
    FOREIGN KEY ([tb_topicsid])
    REFERENCES [dbo].[tb_topics]
        ([topicsid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TopicsInfoCommentsInfo'
CREATE INDEX [IX_FK_TopicsInfoCommentsInfo]
ON [dbo].[tb_comments]
    ([tb_topicsid]);
GO

-- Creating foreign key on [tb_userid] in table 'tb_favorites'
ALTER TABLE [dbo].[tb_favorites]
ADD CONSTRAINT [FK_UserInfoFavoritesInfo]
    FOREIGN KEY ([tb_userid])
    REFERENCES [dbo].[tb_users]
        ([userid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserInfoFavoritesInfo'
CREATE INDEX [IX_FK_UserInfoFavoritesInfo]
ON [dbo].[tb_favorites]
    ([tb_userid]);
GO

-- Creating foreign key on [tb_topicsid] in table 'tb_favorites'
ALTER TABLE [dbo].[tb_favorites]
ADD CONSTRAINT [FK_TopicsInfoFavoritesInfo]
    FOREIGN KEY ([tb_topicsid])
    REFERENCES [dbo].[tb_topics]
        ([topicsid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TopicsInfoFavoritesInfo'
CREATE INDEX [IX_FK_TopicsInfoFavoritesInfo]
ON [dbo].[tb_favorites]
    ([tb_topicsid]);
GO

-- Creating foreign key on [tb_userid] in table 'tb_userattr'
ALTER TABLE [dbo].[tb_userattr]
ADD CONSTRAINT [FK_UserInfoUserAttrInfo]
    FOREIGN KEY ([tb_userid])
    REFERENCES [dbo].[tb_users]
        ([userid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserInfoUserAttrInfo'
CREATE INDEX [IX_FK_UserInfoUserAttrInfo]
ON [dbo].[tb_userattr]
    ([tb_userid]);
GO

-- Creating foreign key on [tb_attributesid] in table 'tb_userattr'
ALTER TABLE [dbo].[tb_userattr]
ADD CONSTRAINT [FK_AttributesInfoUserAttrInfo]
    FOREIGN KEY ([tb_attributesid])
    REFERENCES [dbo].[tb_attributes]
        ([attributesid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AttributesInfoUserAttrInfo'
CREATE INDEX [IX_FK_AttributesInfoUserAttrInfo]
ON [dbo].[tb_userattr]
    ([tb_attributesid]);
GO

-- Creating foreign key on [tb_topicsid] in table 'tb_topicsattr'
ALTER TABLE [dbo].[tb_topicsattr]
ADD CONSTRAINT [FK_TopicsInfoTopicsAttrInfo]
    FOREIGN KEY ([tb_topicsid])
    REFERENCES [dbo].[tb_topics]
        ([topicsid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TopicsInfoTopicsAttrInfo'
CREATE INDEX [IX_FK_TopicsInfoTopicsAttrInfo]
ON [dbo].[tb_topicsattr]
    ([tb_topicsid]);
GO

-- Creating foreign key on [tb_attributesid] in table 'tb_topicsattr'
ALTER TABLE [dbo].[tb_topicsattr]
ADD CONSTRAINT [FK_AttributesInfoTopicsAttrInfo]
    FOREIGN KEY ([tb_attributesid])
    REFERENCES [dbo].[tb_attributes]
        ([attributesid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AttributesInfoTopicsAttrInfo'
CREATE INDEX [IX_FK_AttributesInfoTopicsAttrInfo]
ON [dbo].[tb_topicsattr]
    ([tb_attributesid]);
GO

-- Creating foreign key on [tb_userid] in table 'tb_message'
ALTER TABLE [dbo].[tb_message]
ADD CONSTRAINT [FK_UserInfoMessageInfo]
    FOREIGN KEY ([tb_userid])
    REFERENCES [dbo].[tb_users]
        ([userid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserInfoMessageInfo'
CREATE INDEX [IX_FK_UserInfoMessageInfo]
ON [dbo].[tb_message]
    ([tb_userid]);
GO

-- Creating foreign key on [tb_settingstypeid] in table 'tb_settings'
ALTER TABLE [dbo].[tb_settings]
ADD CONSTRAINT [FK_SettingsTypeInfoSettingsInfo]
    FOREIGN KEY ([tb_settingstypeid])
    REFERENCES [dbo].[tb_settingstype]
        ([settingstypeid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SettingsTypeInfoSettingsInfo'
CREATE INDEX [IX_FK_SettingsTypeInfoSettingsInfo]
ON [dbo].[tb_settings]
    ([tb_settingstypeid]);
GO

-- Creating foreign key on [tb_pageid] in table 'tb_nodes'
ALTER TABLE [dbo].[tb_nodes]
ADD CONSTRAINT [FK_PageInfoNodesInfo]
    FOREIGN KEY ([tb_pageid])
    REFERENCES [dbo].[tb_page]
        ([pageid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PageInfoNodesInfo'
CREATE INDEX [IX_FK_PageInfoNodesInfo]
ON [dbo].[tb_nodes]
    ([tb_pageid]);
GO

-- Creating foreign key on [user_userid] in table 'tb_UserRole'
ALTER TABLE [dbo].[tb_UserRole]
ADD CONSTRAINT [FK_tb_UserRole_UserInfo]
    FOREIGN KEY ([user_userid])
    REFERENCES [dbo].[tb_users]
        ([userid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [role_roleid] in table 'tb_UserRole'
ALTER TABLE [dbo].[tb_UserRole]
ADD CONSTRAINT [FK_tb_UserRole_RoleInfo]
    FOREIGN KEY ([role_roleid])
    REFERENCES [dbo].[tb_role]
        ([roleid])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_tb_UserRole_RoleInfo'
CREATE INDEX [IX_FK_tb_UserRole_RoleInfo]
ON [dbo].[tb_UserRole]
    ([role_roleid]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------